package com.yztc.orangeentertainment.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.facebook.drawee.view.SimpleDraweeView;
import com.yztc.orangeentertainment.R;
import com.yztc.orangeentertainment.base.OnItemClickListener;
import com.yztc.orangeentertainment.bean.channalarticle.ChannalArticleRecommendBean;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by My on 2016/10/10.
 */
public class ChannalArticleJinBaoAdapter extends RecyclerView.Adapter<ChannalArticleJinBaoAdapter
        .MyViewHolder> {
    private Context context;
    private List<ChannalArticleRecommendBean> recommendBeanList;
    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public ChannalArticleJinBaoAdapter(Context context, List<ChannalArticleRecommendBean> recommendBeanList) {
        this.context = context;
        this.recommendBeanList = recommendBeanList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.channal_content_rvitem1, null);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        Glide.with(context).load(recommendBeanList.get(position).getPic()).into(holder
                .ivChannalrvitem1photo);
        holder.tvChannalrvitem1title.setText(recommendBeanList.get(position).getTitle());
        holder.tvChannalrvitem1type.setText(recommendBeanList.get(position).getCat().getName());
        holder.tvChannalrvitem1scanner.setText(recommendBeanList.get(position).getReadnum()+"");
        holder.dvChannalrvitem1icon.setImageURI(recommendBeanList.get(position).getCat().getIcon());
        if (onItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    onItemClickListener.onItemClick(holder.itemView, pos);
                }
            });

            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int pos = holder.getLayoutPosition();
                    onItemClickListener.onItemLongClick(holder.itemView, pos);
                    return false;
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return recommendBeanList.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.tv_channalrvitem1title)
        TextView tvChannalrvitem1title;
        @InjectView(R.id.dv_channalrvitem1icon)
        SimpleDraweeView dvChannalrvitem1icon;
        @InjectView(R.id.tv_channalrvitem1type)
        TextView tvChannalrvitem1type;
        @InjectView(R.id.iv_channalrvitem1scanner)
        ImageView ivChannalrvitem1scanner;
        @InjectView(R.id.tv_channalrvitem1scanner)
        TextView tvChannalrvitem1scanner;
        @InjectView(R.id.iv_channalrvitem1delete)
        ImageView ivChannalrvitem1delete;
        @InjectView(R.id.iv_channalrvitem1photo)
        ImageView ivChannalrvitem1photo;
        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }
}
